//
//  GImageView.m
//  ZLSQ_owner
//
//  Created by ihope99 on 2017/8/12.
//  Copyright © 2017年 iHope. All rights reserved.
//

#import "ZXImageView.h"

@implementation ZXImageView

#define DefaultImage @""

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.placeholderImage = [UIImage imageNamed:DefaultImage];
        self.image =[UIImage imageNamed:DefaultImage];
        self.contentMode = UIViewContentModeScaleAspectFill;
    }
    return self;
}
-(void)setPlaceholderImage:(UIImage *)placeholderImage{
    _placeholderImage = placeholderImage;
    self.image = placeholderImage;
}
-(void)setContentMode:(UIViewContentMode)contentMode{
    [super setContentMode:contentMode];
    if (contentMode == UIViewContentModeScaleAspectFill ) {
        self.layer.masksToBounds = YES;
    }
    else{
        self.layer.masksToBounds = NO;
    }
}

-(void)round{
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = self.frame.size.height/2;
}


-(void)GetImagePath:(id)path{
    if ([path isKindOfClass:[NSString class]]) {
        if ([path hasPrefix:@"http"]) {
            [self sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:self.placeholderImage];
        }
        else if ([path rangeOfString:@"/"].location != NSNotFound){
            self.image = [UIImage imageWithContentsOfFile:path];
        }
        else{
            self.image = [UIImage imageNamed:path];
        }
    }
    else if ([path isKindOfClass:[UIImage class]]){
        self.image = path;
    }
    else{
        [self sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:self.placeholderImage];
    }

}

@end
